<{if $scenic}>
<script>
parent.callback_scenic_add_new (<{$scenic.id}>, <{$scenic.type}>, '<{$scenic.name}>', '<{$scenic.subTitle}>', '<{$scenic.iconUrl}>');
// 当你在iframe页面关闭自身时
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//再执行关闭
parent.layer.close(index);
</script>
<{else}>
<{include file="www/header.tpl"}>
<div id="scenic-add" class="days" style="overflow-x:hidden;overflow-y:scroll;">
    <form action="" method="POST" name="formAdd" enctype="multipart/form-data">

        <label class="line fix">
            <span class="span">景点中文名称</span>
            <input type="text" name="name" placeholder="请输入景点中文名称" class="input">
        </label>

        <label class="line fix">
            <span class="span">景点外文名称</span>
            <input type="text" name="subTitle" placeholder="请输入景点外文名称" class="input">
        </label>

        <label class="line fix">
            <span class="span">景点地址</span>
            <input type="text" name="address" placeholder="请输入景点地址" class="input">
            <input type="hidden" name="lat">
            <input type="hidden" name="lng">
        </label>
        <label class="line fix" id="map-container" style="width: 610px;height: 200px;margin: 0px 0px 10px 40px;border: 1px dotted rgb(70, 208, 139);background: url('/resource/www/imgs/map-preview.png') 241px 36px no-repeat;"></label>

        <label class="line fix">
            <span class="span">景点介绍</span>
            <textarea name="summary" placeholder="请输入景点介绍" class="textarea"></textarea>
        </label>
        
        <label class="line fix">
            <span class="span" style="line-height:20px">景点官方网站<br>(选填)</span>
            <input type="text" name="website" placeholder="请输入景点官方网站" class="input">
        </label>
        
        <label class="line fix">
            <span class="span">开放时间</span>
            <textarea name="descOpenTime" placeholder="例：每周五9:00-20:00,控制在250字之内" class="textarea"></textarea>
        </label>
        
        <label class="line fix">
            <span class="span">票务信息</span>
            <textarea name="descTickets" placeholder="例：成人票 200元/人,控制在250字之内" class="textarea"></textarea>
        </label>

        <label class="line fix">
            <span class="span">景点横幅图</span>
            <div class="upload banner" style="background-size: cover;">
                <input type="file" name="cover">
            </div>
        </label>

        <label class="line fix">
            <span class="span">景点缩略图</span>
            <div class="upload thumb" style="background-size: cover;">
                <input type="file" name="thumb">
            </div>
        </label>

        <label class="line fix">
            <span class="span">景点图片</span>
            <div class="imgbox">
                <!-- <p class="imgtext">至少上传一张，最多4张</p> -->
                <ul class="box fix">
                    <li class="imgli" style="background-size: cover;"><input type='file' class='file' name='images[]'></li>
                </ul>
            </div>
        </label>

        <div class="bottom">
            <input type="button" name="sbt" value="取消" class="cancel" onclick="return layer_close_all()">
            <input type="submit" name="sbt" value="提交" class="ok" onclick="return submit_scenic_add();">
        </div>

    </form>
</div>
<script type="text/javascript" src="http://maps.google.cn/maps/api/js?key=AIzaSyCXDeoGjdaJoF22xDyU0L-cugypMDjxQJY"></script>
<script type="text/javascript">
//上传后生成浏览
$(document).ready(function () {
    
$("input[name=thumb]").change(event_upload_change);
$("input[name=cover]").change(event_upload_change);
$(".imgbox ul.box").delegate("input","change",function(event){
	//第一次上传
	if(!$(this).hasClass("active")){
		$(this).addClass("active");
		var html="<li class='imgli' style='background-size: cover;'><input type='file' class='file' name='images[]'></li>";
		$(this).parent().parent().append(html);
	}
	
	event_upload_change(event);
});

});

function event_upload_change (event) {
	var file = $(event.target)[0].files[0];
	if(file){
		var src = URL.createObjectURL(file);
		$(event.target).parent().css("background-image","url("+src+")");
	}	
	return;
}
//景点介绍的缩放
$("textarea[name='summary']").focus(function(){
	$(this).animate({height:"300px"},"slow","linear");
});
$("textarea[name='summary']").blur(function(){
	$(this).animate({height:"90px"},"slow","linear");
});
//地图
$("input[name='address']").change(function(){
	var address=$(this).val();
	var geocoder = new google.maps.Geocoder();
	geocoder.geocode({ 'address': address }, function (results, status) {
	    if (status == google.maps.GeocoderStatus.OK) {
	        ParseLocation(results[0].geometry.location);
	    }
	    else{
             layer.msg("地址不存在或格式不正确");
             $(this).val('');
	    }
	});
});

function ParseLocation(location) {

    var lat = location.lat().toString().substr(0, 12);
    var lng = location.lng().toString().substr(0, 12);
    console.log("lat:"+lat+"lng:"+lng);
    $("input[name='lng']").val(lng);
    $("input[name='lat']").val(lat);
    
    var myplace,infowindow,marker;
    var myLatlng=new google.maps.LatLng(lat,lng);
    var mapOptions = {
        center: myLatlng,
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    
    var map = new google.maps.Map(document.getElementById("map-container"),
            mapOptions);
    
    marker = new google.maps.Marker({
        map: map,
        position: myLatlng
    });
    
    infowindow = new google.maps.InfoWindow({
    	content:"此处为您输入的地址"
    });
    infowindow.open(map,marker);

}

function layer_close_all ()
{
    // 当你在iframe页面关闭自身时
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    //再执行关闭
    parent.layer.close(index);
    return false;
}
</script>

<script>

function submit_scenic_add() {

    var oName = $('#scenic-add').find("input[name='name']").val();
    oName=$.trim(oName);
    if (!oName) {
        layer.msg('请输入景点中文名称');
        return false; 
    }
    if(oName.length>20){
    	layer.msg("请控制景点中文名称在20字以内");
    	return false;
    }

    var oSubTitle = $('#scenic-add').find("input[name='subTitle']").val();
    oSubTitle=$.trim(oSubTitle);
    if (!oSubTitle) {
        layer.msg('请输入景点外文名称');
        return false;
    }
    if(oSubTitle.length>50){
    	layer.msg("景点外文名称过长");
    	return false;
    }

    var oAddress = $('#scenic-add').find("input[name='address']").val();
    if (!$.trim(oAddress)) {
        layer.msg('请输入景点地址');
        return false;
    }
    
    var oWebsite = $('#scenic-add').find("input[name='website']").val();
    oWebsite=$.trim(oWebsite);
    if(oWebsite.length>100){
    	layer.msg("景点官方网站地址过长");
    	return false;
    }

    var oSummary = $('#scenic-add').find("textarea[name='summary']").val();
    if (!$.trim(oSummary)) {
        layer.msg('请输入景点介绍');
        return false;
    }
    
    var odescOpenTime = $('#scenic-add').find("textarea[name='descOpenTime']").val();
    odescOpenTime=$.trim(odescOpenTime);
    if (!odescOpenTime) {
        layer.msg('请输入开放时间');
        return false;
    }
    if(odescOpenTime.length>250){
    	layer.msg('开放时间字数超过250字');
        return false;
    }
    
    
    var odescTickets = $('#scenic-add').find("textarea[name='descTickets']").val();
    odescTickets=$.trim(odescTickets);
    if (!odescTickets) {
        layer.msg('请输入票务信息');
        return false;
    }
    if(odescTickets.length>250){
    	layer.msg('票务信息字数超过250字');
        return false;
    }

    if($('input:file[name="cover"]').val() == ''){
       layer.msg('请选择景点横幅图');
       return false;
    }

    if($('input:file[name="thumb"]').val() == ''){
       layer.msg('请选择景点缩略图');
       return false;
    }

    var oFile = 1;
    $("input[name='images[]']").each(function(){
        if( $(this).val() != "" ) {
            oFile = 0;
        }
    });
    if (oFile) {
        layer.msg('请选择景点图片');
        return false;
    }

    layer.msg("资料上传中，请等待...");
    layer.load(0);

    return true;
}

</script>

<{/if}>
